package xjtu.se.articlecommunity.admin.busermanage;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xjtu.se.articlecommunity.admin.busermanage.dto.User;
import xjtu.se.articlecommunity.common.MailService;
import xjtu.se.articlecommunity.common.Result;
import xjtu.se.articlecommunity.common.SMSService;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/busermanage")
public class ManageAPI {
    @Resource
    private ManageService manageService;

    @Resource
    private SMSService smsService;

    @Resource
    private MailService mailService;

    // 查看后台管理人员
    @RequestMapping("/getBUserList")
    public Result getBUserList() {
        return Result.success(manageService.getBUserList());
    }

    // 查看后台管理人员
    @RequestMapping("/getBUserApplyList")
    public Result getBUserApplyList() {
        return Result.success(manageService.getBUserApplyList());
    }

    // 删除后台管理人员
    @RequestMapping("/delete")
    public Result delete(@RequestBody User user) {
        manageService.delete(user);
        return Result.success();
    }
    // 新增后台管理人员
    @RequestMapping("/new")
    public Result newBUser(@RequestBody User user) {
        manageService.newBUser(user);
        if(user.getU_tel()!=null) smsService.sendRegistrationSuccessNotification(user.getU_tel(), user.getU_id());
        if(user.getU_mail()!=null) mailService.sendRegistrationSuccessNotification(user.getU_mail());
        return Result.success(user);
    }

}
